<#include "/common/layout.html"> 
<@body>
<div class="content">
	<form class="form-horizontal" method="post" action="/system/user/doAdd" id="userAddFrom">
		<div class="box-body">
			<div class="form-group">
				<label for="uname" class="col-sm-2 control-label">用户名</label>
				<div class="col-sm-10">
					<input type="text" id="userName" name="userName" class="form-control" placeholder="请输入用户名" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">部门</label>
				<div class="col-sm-10">
					<select name="deptId" class="form-control select2" style="width:100%;" required>
						<#list deptList as dept>
							<option value="${(dept.deptId)!}">${(dept.deptName)!}</option>
						</#list>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="password" class="col-sm-2 control-label">密码</label>
				<div class="col-sm-10">
					<input type="password" class="form-control" id="password" name="password" placeholder="请输入密码" required>
				</div>
			</div>
			<div class="form-group">
				<label for="password2" class="col-sm-2 control-label">确认密码</label>
				<div class="col-sm-10">
					<input type="password" class="form-control" id="password2" name="password2" placeholder="请输入确认密码" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">描述</label>
				<div class="col-sm-10">
					<textarea class="form-control" id="userDesc" name="userDesc" rows="3" placeholder="请输入描述，最多300个字符 ..." required></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">状态</label>
				<div class="col-sm-10">
					<label class="radio-box"> 
						<input name="userState" type="radio" class="minimal" checked value="1" required> 启用
					</label> 
					<label> 
						<input name="userState" type="radio"class="minimal" value="-1"> 禁用
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">角色分配</label>
				<div class="col-sm-10">
					<#list roleList as role> 
					<label class="check-box" title="${(role.roleDesc)!}"> 
						<input type="checkbox" name="roleId[]" class="minimal" value="${(role.roleId)!}">
						${(role.roleName)!}
					</label> &nbsp;
					</#list>
				</div>
			</div>
		</div>
	</form>
</div>
</@body> 
<script type="text/javascript">
	var icon = "<i class='fa fa-times-circle'></i>";
	$("#userAddFrom").validate({
		rules:{
			userName: {
				required: true,
				minlength: 5,
				remote: "/system/user/checkName"
			},
			password: {
				required: true,
				minlength: 6
			},
			password2: {
				required: true,
				minlength: 6,
				equalTo: "#password"
			},
		},
		messages: {
			userName: {
				remote: jQuery.validator.format(icon + "该用户名已存在")
			},
			password2: {
				equalTo: jQuery.validator.format(icon + "输入密码不一致")
			},
		},
		focusCleanup: true
	});
	function submitHandler() {
		if ($("#userAddFrom").validate().form()) {
			var formData = $("#userAddFrom").serialize();
			$.ajax({
				url : $("#userAddFrom").attr('action'),
				type : 'POST',
				dataType: "json",
				data : formData,
				beforeSend : function() {
					$.modal.loading("正在处理中，请稍后...");
					$.modal.disable();
				},
				success : function(data) {
					if (data.code == 200) {
						if (data.msg) {
							parent.layer.msg(data.msg, {
								icon : 1
							});
						} else {
							parent.layer.msg('提交成功', {
								icon : 1
							});
						}
						parent.layer.closeAll('iframe'); // 关闭当前frame
						window.parent.data_oTable.draw(false);
					} else {
						layer.msg(data.msg, {
							icon : 2
						});
						$.modal.closeLoading();
						$.modal.enable();
					}
				}
			});
		}
	}
</script> 
